package com.info.protocol.serial;

import java.util.HashMap;
import java.util.Map;

public class SerializerManager {

    private static final Map<Integer, Serializer> serializerMap = new HashMap<>(2);

    static {
        Serializer jdkSerializer = new JdkSerializer();
        Serializer jsonSerializer = new JsonSerializer();
        serializerMap.put((int) jdkSerializer.getType(), jdkSerializer);
        serializerMap.put((int) jsonSerializer.getType(), jsonSerializer);
    }

    public static Serializer getSerializerByCode(int code) {
        Serializer serializer = serializerMap.get(code);
        if (serializer == null) {
            serializer = new JdkSerializer();
        }
        return serializer;
    }
}
